package com.dyz.leetcode._20_dynamicProgramming._416;

public class canPartition01 {
    public boolean canPartition(int[] nums) {

        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
        }
        int target = sum /2;
        if(sum%2!=0){return false;}

        //dp

        boolean[] dp = new boolean[target+1];
        dp[0] = true;
        for (int i = 0; i <nums.length ; i++) {
            for (int j = target; j >=nums[i] ; j--) {
                dp[j] = dp[j] || dp[j-nums[i]];
            }
        }
        return dp[target];

    }
}
